package com.ccp.dev.qbdms.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.poi.excel.Excel;
import com.ccp.dev.qbdms.dao.WQbdFlightJczbDao;
import com.ccp.dev.qbdms.model.WQbdFlightJczb;
import java.util.Date;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * 飞行试验奖惩管理子 信息操作服务类
 *
 * @author 于金
 * @date 2020-05-25 16:46:07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WQbdFlightJczbService extends BaseService<WQbdFlightJczb> {

    @Resource
    private WQbdFlightJczbDao dao;

    public HSSFWorkbook exportExcel(Excel excel,QueryFilter queryFilter){
    List<WQbdFlightJczb> dataList = this.dao.queryAll(queryFilter);
        int startRow = 1;
        //给每一个单元格赋值
        for (WQbdFlightJczb data : dataList) {
            excel.cell(startRow, 0).value(data.getId());
            //excel.cell(startRow, 1).value(data.getMc());
            //可在赋值时，根据需求进行格式化
            //excel.cell(startRow, 2).value(DateFormatUtil.formatDate(data.getRq()));
            //excel.cell(startRow, 3).value(data.getSj());
            //excel.cell(startRow, 4).value(data.getTenantId());
            startRow++;
        }
        return excel.getWorkBook();
    }

    public List<WQbdFlightJczb> getListByRefId(Map<String,Object> paramMap) {
        return dao.getListByRefId(paramMap);
    }

    public void update(List<List<WQbdFlightJczb>> wQbdFlightJczbList) {
        for (List<WQbdFlightJczb> list : wQbdFlightJczbList) {
            for (WQbdFlightJczb wQbdFlightJczb : list) {
                wQbdFlightJczb.setReleaseTime(new Date());
                dao.update(wQbdFlightJczb);
            }
        }
    }

    public boolean judgeReport(String ids) {
        String[] idArray = ids.split(",");
        WQbdFlightJczb wQbdFlightJczb;
        for (String id : idArray) {
            wQbdFlightJczb = dao.getById(id);
            if (null == wQbdFlightJczb || null == wQbdFlightJczb.getSjjled()) {
                return false;
            }
        }
        return true;
    }
}
